/**
 * created by dqn
 * 2018/5/12--19:09
 */

package me.dqn.callback;

import me.dqn.aspect.ProxyAspect;
import me.dqn.proccesor.ProcessJoinPoint;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * around me.dqn.callback
 * around callback
 * @author dqn
 */
public class AroundCallback implements MethodInterceptor {
    Class<? extends ProxyAspect> aspect;

    public AroundCallback(Class<? extends ProxyAspect> aspect) {
        this.aspect = aspect;
    }

    /**
     * 调用代理切面的doAround方法，并把原来的方法等信息传过去
     * @param o
     * @param method
     * @param objects
     * @param methodProxy
     * @return
     * @throws Throwable
     */
    @Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        ProxyAspect proxyAspect = aspect.newInstance();
        return proxyAspect.doAround(new ProcessJoinPoint(o,methodProxy,objects));
    }
}
